package jp.co.recruit_lifestyle.sample.slice;

import jp.co.recruit_lifestyle.sample.ResourceTable;
import ohos.agp.components.*;
import ohos.app.Context;

import java.util.ArrayList;
import java.util.List;

public class ArrayAdapter extends BaseItemProvider {

    private List<String> dataList = new ArrayList<>();

    private Context mContext;

    public ArrayAdapter(Context context, List<String> dataList) {
        this.mContext = context;
        this.dataList = dataList;
    }

    @Override
    public int getCount() {
        return dataList.size();
    }

    @Override
    public Object getItem(int i) {
        return dataList.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public Component getComponent(int i, Component convertComponent, ComponentContainer componentContainer) {
        final Component cpt;
        if (convertComponent == null) {
            cpt = LayoutScatter.getInstance(mContext).parse(ResourceTable.Layout_item_array, componentContainer, false);
        } else {
            cpt = convertComponent;
        }
        return cpt;
    }
}
